<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="js/jquery-1.9.1.min.js"></script>
		<script src="js/bootstrap.min.js"></script>
		<script src="js/bootstrap-suggest.min.js"></script>
		<link rel="stylesheet" href="css/common.css">
		<link rel="stylesheet" href="css/bootstrap.min.css">
		<link rel="stylesheet" type="text/css" href="css/StudentInformation.css"/>
	</head>
	<body>
	<form id="class"  method="post">
		<table class="table table-bordered" >
			<tbody>
			<tr>
				<th scope="row">授课老师</th>
				<td><div class="input-group">
						<input type="text" class="form-control" id="tx1" name="teacher" >
						<div class="input-group-btn">
							<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
								<span class="caret"></span>
							</button>
							<ul class="dropdown-menu dropdown-menu-right" role="menu">
							</ul>
						</div>
						<!-- /btn-group -->
					</div></td>
			</tr>
			<tr>
				<th scope="row">班长</th>
				<td><div class="input-group">
						<input type="text" class="form-control" id="tx2" name="student" >
						<div class="input-group-btn">
							<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
								<span class="caret"></span>
							</button>
							<ul class="dropdown-menu dropdown-menu-right" role="menu">
							</ul>
						</div>
						<!-- /btn-group -->
					</div></td>
			</tr>
			<tr>
				<th scope="row">班主任</th>
				<td><div class="input-group">
						<input type="text" class="form-control" id="tx3" name="banteacher" >
						<div class="input-group-btn">
							<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
								<span class="caret"></span>
							</button>
							<ul class="dropdown-menu dropdown-menu-right" role="menu">
							</ul>
						</div>
					</div></td>
			</tr>
			<tr>
				<th scope="row">班级名称</th>
				<td>
					<div class="input-group">
						<input type="text" class="form-control"  name="classname"  id="classid">
					</div>
				</td>
			</tr>
			<tr>
				<th scope="row">专业</th>
				<td>
					<div class="input-group">
						<input type="text" class="form-control" id="tx4" name="major" >
						<div class="input-group-btn">
							<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
								<span class="caret"></span>
							</button>
							<ul class="dropdown-menu dropdown-menu-right" role="menu">
							</ul>
						</div>
					</div>
				</td>
			</tr>
			<tr>
			<th scope="row">课程阶段</th>
			<td>
				<div class="input-group">
					<input type="text" class="form-control"  name="stage" id="stageid" >

				</div>
			</td>
			</tr>
			<tr>
				<th scope="row">开课日期</th>
				<td>
					<div class="input-group">
						<input type="date" class="form-control"  name="start_date" id="start_dateid" >
					</div>
				</td>
			</tr>
			<tr>
				<th scope="row">结课日期</th>
				<td>
					<div class="input-group">
						<input type="date" class="form-control"  name="end_date" id="end_dateid" >
					</div>
				</td>
			</tr>

			</tbody>

		</table>
		<button id="save" type="button"class="btn btn-default" >添加</button>
	</form>

	<script>
		var bsSuggest = $("#tx1").bsSuggest({
			url: "/hello?keyword=",
			getDataMethod:"url",
			idField: "id",
			keyField: "username",
			effectiveFields: ["username", "id","email","phone"],
			effectiveFieldsAlias: { username: "名字",id:"编号",email:"邮箱",phone:"手机" },
			showHeader: true,//显示 header
			showBtn: true,   //不显示下拉按钮
			delayUntilKeyup: false, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
		});
		var bsSuggest = $("#tx2").bsSuggest({
			url: "/hello?keyword=",
			getDataMethod:"url",
			idField: "id",
			keyField: "username",
			effectiveFields: ["username", "id","email","phone"],
			effectiveFieldsAlias: { username: "名字",id:"编号",email:"邮箱",phone:"手机" },
			showHeader: true,//显示 header
			showBtn: true,   //不显示下拉按钮
			delayUntilKeyup: false, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
		});
		var bsSuggest = $("#tx3").bsSuggest({
			url: "/hello?keyword=",
			getDataMethod:"url",
			idField: "id",
			keyField: "username",
			effectiveFields: ["username", "id","email","phone"],
			effectiveFieldsAlias: { username: "名字",id:"编号",email:"邮箱",phone:"手机" },
			showHeader: true,//显示 header
			showBtn: true,   //不显示下拉按钮
			delayUntilKeyup: false, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
		});
		var bsSuggest = $("#tx4").bsSuggest({
			url: "/major?keyword=",
			getDataMethod:"url",
			idField: "id",
			keyField: "name",
			effectiveFields: ["name"],
			effectiveFieldsAlias: { name: "专业名称"},
			showHeader: true,//显示 header
			showBtn: true,   //不显示下拉按钮
			delayUntilKeyup: false, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
		});

		/*$("#teacher").on("dataRequestSuccess", function (event, result) {
			console.log(result);
		});*/
		$('#save').on('click',function(){
			$.ajax({
				//几个参数需要注意一下
				type: "POST",//方法类型
				dataType: "json",//预期服务器返回的数据类型
				url: "/admin/class/save" ,//url
				data: {
					teacher:$("#tx1").attr("data-id"),
					student:$("#tx2").attr("data-id"),
					banteacher:$("#tx3").attr("data-id"),
					maior:$("#tx4").attr("data-id"),
					classname:$("#classid").val(),
					stage:$("#stageid").val(),
					start_date:$("#start_dateid").val(),
					nd_date:$("#end_dateid").val()

				},
				success: function (result) {
					//     console.log(result);//打印服务端返回的数据(调试用)
					if (result.code == 200) {
						alert("添加成功");
					};
					if (result.code == 100) {
						alert("班级名称已存在  亲 —**—");
					};
				},
				// error : function() {
				//     alert("异常！");
				// }
			});

		});

	</script>
	</body>
</html>
